package com.wn.consumer03;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author yellow Docter
 * @date 2023 -02-28
 * @desc
 * 测试 路由模式 的消息模型
 *
 *  交换机通过路由 给不同的队列发送消息
 *
 *  ExchangeTypes.FANOUT
 *         通过 广播的方式给所有绑定的队列发送消息
 *  ExchangeTypes.DIRECT
 *        通过 routingkey 给  不同的 队列发送消息
 */
@Component
@Slf4j
public class LogConsumer {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @RabbitListener(
            bindings = @QueueBinding(
                    value = @Queue(name = "queue-direct-log"),
                    exchange = @Exchange(
                            name = "direct-log",
                            type = ExchangeTypes.DIRECT
                    ),
                    key = {"info","error","warning"}
            )
    )
    public void handlerMsg(String msg){
            log.info("LogConsumer 的消费者消息消息是:{}",msg);
    }
}
